﻿using System;
using System.Diagnostics;
using System.Drawing;
using Microsoft.WowAddonStudio.FrameXml.Services;

namespace Microsoft.WowAddonStudio.FrameXml.Components.Editors
{
    public class TextureTreePickerEditorForm : TreePickerEditorForm
    {
        public TextureTreePickerEditorForm(PickerElement tree, IServiceProvider provider) : base(tree, provider)
        {
        }

        protected override void ShowPreview()
        {
            base.ShowPreview();

            try
            {
                if (!string.IsNullOrEmpty(RelativePath))
                {
                    Image previewImage = ImageService.GetImage(RelativePath);

                    if (previewImage != null)
                    {
                        previewPictureBox.Image = previewImage;
                    }
                }
            }
            catch (Exception e)
            {
                Trace.Write(e);
                previewPictureBox.Image = null;
            }
        }

        private FrameXmlImageService ImageService
        {
            get { return (FrameXmlImageService) provider.GetService(typeof (FrameXmlImageService)); }
        }
    }
}
